package com.docMan.utils;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.docMan.lucene.Indexer;

public class IndexUpdate {
	 static String sql1578 = "select RECID,SWBH,LWBH,TO_CHAR(INSHEETDATE,'yyyy-mm-dd'),LWDW,LWBT,INSHEETDATE,FIELD11583 from TZREC1578 where INSHEETDATE>=? and INSHEETDATE is not null ORDER BY INSHEETDATE ";
	 static String sql1830 = "select RECID,SWBH,LWBH,TO_CHAR(INSHEETDATE,'yyyy-mm-dd'),LWDW,LWBT,INSHEETDATE,FIELD11582 from TZREC1830 where INSHEETDATE>=? and INSHEETDATE is not null ORDER BY INSHEETDATE ";
	 static String sql1963 = "select RECID,SWBH,LWBH,TO_CHAR(INSHEETDATE,'yyyy-mm-dd'),LWDW,LWBT,INSHEETDATE,'否' from TZREC1963 where INSHEETDATE>=? and INSHEETDATE is not null ORDER BY INSHEETDATE ";
	public static void main(String[] args) throws IOException, SQLException, ParseException {
		long time=1481216400028l;
		Date date=new Date(time);
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		System.out.println(simpleDateFormat.format(new java.util.Date(time)));
		Indexer indexer=Indexer.getInstance(FinalConfig.index_dir);
		dbUtils dbu = new dbUtils();
		
			sql1578="select RECID,FIELD11583,INSHEETDATE from TZREC1578 ";
			ResultSet rSet=dbu.executeQueryRS(sql1578, null);
			Map<String, Map<String, Object>> updateMap=new HashMap<String, Map<String,Object>>();
			while(rSet.next()){
				Map<String, Object> fields=new HashMap<String, Object>();
				fields.put("isImportantFile", null == rSet.getString(2) ? "否"
						: "是".equals(rSet.getString(2).trim()) ? "是": "否");
				fields.put("date", rSet.getDate(3));
				updateMap.put(rSet.getString(1), fields);
			}
			indexer.updateBatch(updateMap);
		
			updateMap.clear();
			sql1830="select RECID,FIELD11582,INSHEETDATE from TZREC1830";
			 rSet=dbu.executeQueryRS(sql1830, null);
			while(rSet.next()){
				Map<String, Object> fields=new HashMap<String, Object>();
				fields.put("isImportantFile", null == rSet.getString(2) ? "否"
						: "是".equals(rSet.getString(2).trim()) ? "是": "否");
				fields.put("date", rSet.getDate(3));
				updateMap.put(rSet.getString(1), fields);
			}
			indexer.updateBatch(updateMap);
			updateMap.clear();
			sql1963="select RECID,'否',INSHEETDATE from TZREC1963 ";
			 rSet=dbu.executeQueryRS(sql1963, null);
			while(rSet.next()){
				Map<String, Object> fields=new HashMap<String, Object>();
				fields.put("isImportantFile", "否");
				fields.put("date", rSet.getDate(3));
				updateMap.put(rSet.getString(1), fields);
			}
			indexer.updateBatch(updateMap);
	}
	
	
}
